//
//  LoginViewController.m
//  FaceTo
//
//  Created by 程邦明 on 2017/8/22.
//  Copyright © 2017年 chengbangming. All rights reserved.
//

#import "LoginViewController.h"
#import "AppDelegate.h"
#import "TabBarViewController.h"
#import "NavigationViewController.h"
#import "FTSideViewController.h"

@interface LoginViewController ()
@property (nonatomic, strong) TabBarViewController *tabbarVc;
@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
}
- (void)initUI{
    _passwd.secureTextEntry = YES;
}
- (IBAction)loginBtn:(UIButton *)sender {
    [SVProgressHUD showProgress:-1];
    if(_UserName.text.length != 11 || _passwd.text.length == 0){
        [SVProgressHUD showErrorWithStatus:@"请填写正确的用户名和密码"];
    }else{
        [CUseHttpTool loginWithidentification:_UserName.text password:_passwd.text Success:^(loginModel *model) {
            if([model.code isEqualToString:@"200"]){
                [SVProgressHUD showSuccessWithStatus:@"登录成功"];
                [FTUserDefault setObject:@"login" forKey:@"loginSwitch"];
                AppDelegate * delegate = [UIApplication sharedApplication].delegate;
                _tabbarVc = [[TabBarViewController alloc] init];
                CKLeftSlideViewController *root = [[CKLeftSlideViewController alloc] initWithLeftVc:[FTSideViewController new] mainVc:_tabbarVc];
                delegate.window.rootViewController = root;
                
            }else{
                [SVProgressHUD showSuccessWithStatus:model.msg];
            }
        } failure:^(NSError *error) {
            if(error){
                [SVProgressHUD showErrorWithStatus:@"服务器繁忙"];
            }
        }];
    }
}
- (IBAction)cannotlogin:(UIButton *)sender {
    
}
- (IBAction)registerBtn:(UIButton *)sender {
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
